package com.zb.network.controller;


import com.zb.entity.AccounLoginInfo;
import com.zb.entity.ExportFieldVo;
import com.zb.network.service.ConNetworkFieldExportService;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjNetworkFieldExportService;
import com.zb.service.ZjNetworkFieldService;
import com.zb.utils.TokenUtil;
import com.zb.vo.NetworkExportAndSaveFieldVo;
import com.zb.vo.WorkExportAndSaveFieldVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * <p>
 * 服务商字段导出表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2024-03-05
 */
@Api(tags = "服务商字段导出类接口")
@RestController
@RequestMapping("/network/field/export")
public class ZjNetworkFieldExportController {
    @Resource
    private ConNetworkFieldExportService conNetworkFieldExportService;
    @Resource
    private ZjNetworkFieldExportService networkFieldExportService;
    @Resource
    private ZjNetworkFieldService networkFieldService;

    @ApiOperation("获取服务商初始化系统导出字段")
    @GetMapping("/getNetworkSysInitExportField")
    public Result getNetworkSysInitExportFields() {
        return Result.success("获取服务商初始化系统导出字段成功").data(PageUtil.rows(networkFieldExportService.getNetworkSysInitExportFields()));
    }

    @ApiOperation("获取服务商自定义字段")
    @GetMapping("/getNetworkCustomField")
    public Result getNetworkCustomField(HttpServletRequest request) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取服务商自定义字段成功").data(PageUtil.rows(networkFieldService.getNetworkCustomField(custAccId)));
    }

    @ApiOperation("获取所有服务商导出字段")
    @GetMapping("/getNetworkExportFields")
    public Result getNetworkExportFields(HttpServletRequest request) {
        AccounLoginInfo loginInfo = TokenUtil.getAccountLoginInfo(request);
        return Result.success("获取所有服务商导出字段成功").data(PageUtil.rows(networkFieldExportService.getNetworkExportFields(loginInfo)));
    }

    @ApiOperation("保存服务商导出字段")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid ExportFieldVo fieldVo) {
        AccounLoginInfo loginInfo = TokenUtil.getAccountLoginInfo(request);
        networkFieldExportService.save(loginInfo, fieldVo);
        return Result.success("保存服务商导出字段成功");
    }

    @ApiOperation("保存并导出服务商字段")
    @PostMapping("/saveAndExportNetworkField")
    public void saveAndExportNetworkField(HttpServletRequest request, HttpServletResponse response,
                                            @RequestBody @Valid NetworkExportAndSaveFieldVo exportFieldVo) {
        AccounLoginInfo loginInfo = TokenUtil.getAccountLoginInfo(request);
        networkFieldExportService.save(loginInfo, exportFieldVo.getExportFieldVo());
        conNetworkFieldExportService.networkExportField(response, loginInfo, exportFieldVo);
    }

}
